package cn.wangchao.org.controller;

import cn.wangchao.basic.util.AjaxResult;
import cn.wangchao.basic.util.PageList;
import cn.wangchao.org.domain.Systemdictionarytype;
import cn.wangchao.org.query.SystemdictionarytypeQuery;
import cn.wangchao.org.service.ISystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/typ")
@RestController
public class SystemdictionarytypeController {
    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeService;

    /**
     * id查询get
     */
    @GetMapping("/{id}")
    public Systemdictionarytype queryById(@PathVariable("id") Long id){
        return systemdictionarytypeService.queryById(id);
    }
    /**
     * 全部查询get
     */
    @GetMapping
    public List<Systemdictionarytype> queryAll(){
        return systemdictionarytypeService.queryAll();
    }


    /**
     * 修改or新增 put
     */
    @PutMapping
    public AjaxResult addOrUpt(@RequestBody Systemdictionarytype systemdictionarytype){
        try {
            if (systemdictionarytype.getId()==null){
                systemdictionarytypeService.save(systemdictionarytype);
            }else {
                systemdictionarytypeService.update(systemdictionarytype);
            }
            return AjaxResult.my();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("哦豁,系统无了,在鞭尸程序猿");
        }


    }

    /**
     * 删除delete
     */
    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable("id") Long id){
        try {
            systemdictionarytypeService.remove(id);
            return AjaxResult.my();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("哦豁,删除瓦了,在鞭尸程序猿");
        }
    }

    /**
     * 高级查询分页-post
     */
    @PostMapping
    public PageList<Systemdictionarytype> querypage(@RequestBody SystemdictionarytypeQuery query){

        return systemdictionarytypeService.queryPage(query);
    }

    /**
     * 批量操作patch
     */
    @PatchMapping
    public AjaxResult batchRemove(@RequestBody List<Long> ids){
        try {
            systemdictionarytypeService.batchRemove(ids);
            return AjaxResult.my();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("哦豁,删除瓦了,在鞭尸程序猿");
        }
    }

}
